/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package EntityGameObject;

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author Khoa
 */
public class PlayPet extends Sprite {

    public static final int WIDTH = 45;
    public static final int HEIGHT = 63;
    
    /**
     * @return the name
     */
    public static String getName() {
        return name;
    }

    /**
     * @param aName the name to set
     */
    public static void setName(String aName) {
        name = aName;
    }
    private int xRefPos;
    private int yRefPos;
    private int displayWidth;
    private int displayHeight;
    private Image imagePet;
    
    private int level;
    private int speed;
    private int stamina;
    private static String name;

    public PlayPet(Image image, int displaywidth, int displayheight) {
        
        super(image);
        imagePet = image;
        this.displayWidth = displaywidth;
        this.displayHeight = displayheight;
        
        defineReferencePixel(imagePet.getWidth() / 2, 0);
      //  xRefPos = (this.displayWidth - imagePet.getWidth() / 2) / 2;
      //  yRefPos = this.displayHeight - imagePet.getHeight();
        xRefPos = this.displayWidth / 2 - 45;
        yRefPos = this.displayHeight - 70;
        setRefPixelPosition(xRefPos , yRefPos );
        setVisible(false);
        speed = 1 + 1;
        stamina = 10;
       
        
    }
    
    public PlayPet(Image image, int displaywidth, int displayheight, int speed, int stamina, int level) {
        
        super(image);
        imagePet = image;
        this.displayWidth = displaywidth;
        this.displayHeight = displayheight;
        
        defineReferencePixel(imagePet.getWidth() / 2, 0);
        xRefPos = this.displayWidth / 2 - 45;
        yRefPos = this.displayHeight - 70;
        setRefPixelPosition(xRefPos , yRefPos );
        setVisible(false);
        this.speed = speed;
        this.stamina = stamina;
        this.level = level;
        
        
    }

    public void UpdateInGame(int gameTicks) {
        setVisible(true);             
    }
    
    public void SetPetRotation(int x, int y)
    {
        
        float d = yRefPos + imagePet.getHeight() / 2 - y;
        float k = xRefPos + imagePet.getWidth() / 2 - x;
        float h = (float)Math.sqrt(d*d + k*k);
        float sinrads = d / h;
        float cosrads = k / h;
        Image imageRotate = Supporter.ImageSupporter.rotateImage(imagePet,sinrads,cosrads );
        setImage(imageRotate, imagePet.getWidth(), imagePet.getHeight());
      //  imagePet = Supporter.ImageSupporter.rotateImage(imagePet,60);
      //  setImage(imagePet, imagePet.getWidth(), imagePet.getHeight());
     //   xRefPos = (this.displayWidth - imagePet.getWidth() / 2) / 2;
     //   yRefPos = this.displayHeight - imagePet.getHeight();
        setRefPixelPosition(xRefPos , yRefPos ); 
        setVisible(true);
    }

    /**
     * @return the speed
     */
    public int getSpeed() {
        return speed;
    }

    /**
     * @param speed the speed to set
     */
    public void setSpeed(int speed) {
        this.speed = speed;
    }

    /**
     * @return the stamina
     */
    public int getStamina() {
        return stamina;
    }

    /**
     * @param stamina the stamina to set
     */
    public void setStamina(int stamina) {
        this.stamina = stamina;
    }

    /**
     * @return the level
     */
    public int getLevel() {
        return level;
    }

    /**
     * @param level the level to set
     */
    public void setLevel(int level) {
        this.level = level;
    }

    

    
}
